/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package socof_trab1;

import java.net.URL;
import java.util.Date;

public class File {
    // private DBAccess db = new DBAccess();

    private int id;
    private String domain;
    private String filename;
    private String localPath;
    private FileStatus status;
    private String tamanhosite;
    private URL sourceUrl;
    private String type;
    private int level;
    private Date lastUpdated;

    public File() {
    }

    public File(URL url) {
        this.sourceUrl = url;

        // fill other elements from url
    }

    public static File getNextToDownload() {
        // go to db and get next item to be downloaded
        return new File();
    }

    public static File getNextToParse() {
        // go to db and get next item to be parsed
        return new File();
    }

    public boolean saveToDb() {
        // saves file to db with status pending
        this.status = FileStatus.PENDING;
        return true;
    }

    public boolean setStatusDownloading() {
        // updates file to db with status DOWNLOADING
        this.status = FileStatus.DOWNLOADING;
        return true;
    }

    public boolean setStatusToParse() {
        // updates file to db with status TO_PARSE
        this.status = FileStatus.TO_PARSE;
        return true;
    }

    public boolean setStatusParsing() {
        // updates file to db with status PARSING
        this.status = FileStatus.PARSING;
        return true;
    }

    public boolean setStatusComplete() {
        // updates file to db with status COMPLETE
        this.status = FileStatus.COMPLETE;
        return true;
    }

    public boolean download() {
        this.setStatusDownloading();

        // Download the file using URL to correct location

        // if (html) this.setStatusToParse();
        // else this.setStatusComplete();

        return true;
    }

    public boolean parse() {
        this.setStatusParsing();

        // Parse the file using

        this.setStatusComplete();

        return true;
    }

    public enum FileStatus {

        PENDING,
        DOWNLOADING,
        TO_PARSE,
        PARSING,
        COMPLETE
    };
}
